(function (window, $, undefined) { var _block_namespaces_ = window._block_namespaces_ || (window._block_namespaces_ = {}); var name = "downloadList_28242"; var downloadList_28242 = _block_namespaces_[name] || (_block_namespaces_[name] = {}); $.extend(downloadList_28242, { "init": init, }) function init(nodeObj) { var $selector = $("[data-new-auto-uuid=" + nodeObj.nodeId + "]"); //直接下载方法 function downloadFile(url, fileName) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'blob'; xhr.onload = function () { if (xhr.status === 200) { var blob = xhr.response; var downloadLink = document.createElement('a'); downloadLink.href = URL.createObjectURL(blob); downloadLink.download = fileName; downloadLink.click(); } }; xhr.send(); } //复制 function copyToClipboard(text) { var $tempInput = $(''); $('body').append($tempInput); $tempInput.val(text).select(); document.execCommand('copy'); $tempInput.remove(); } //成功反馈 function showSuccessBox(message) { var successBox = $('
' + message + '
'); $('body').append(successBox); successBox.fadeIn(); setTimeout(function () { successBox.fadeOut(function () { successBox.remove(); }); }, 2000); } //打开预览 function openPreviewImg(targetDom) { var downImgUrl = '//' + targetDom.attr("data-href"); var previewImgUrl = targetDom.attr("data-new_file_url"); var fileExtension = targetDom.attr("data-type"); if (fileExtension === 'jpg' || fileExtension === 'jpeg' || fileExtension === 'png' || fileExtension === 'gif' || fileExtension === 'svg') { $("body").append('
'); try { $("#box-preview-img").lightGallery({ thumbnail: false }); } catch (error) { console.log(error) } $("#box-preview-img").find("img").click(); setTimeout(function () { $("#box-preview-img").remove(); $('#lg-zoom-in').addClass('fa'); $(".lg-toolbar").find("#lg-download").attr("href", downImgUrl); }, 200); } else { var fileName = targetDom.attr('data-name') downloadFile(targetDom.attr('data-href'), fileName); } } function opeart() { $selector.find('.copyLink-btn').on('click', function () { if ($(this).attr('data-url')) { copyToClipboard($(this).attr('data-url')); showSuccessBox($selector.find('#copyMsg').val()); } }) //图片预览下载 $selector.find('.preview-file').unbind('click').bind('click', function (event) { event.preventDefault(); event.stopPropagation(); openPreviewImg($(this)); }) $selector.find('.downFile').unbind('click').bind('click', function (event) { var fileName = $(this).attr('data-name'); downloadFile($(this).attr('data-href'), fileName); }) } opeart(); var props = { "elem": $selector.find('.downloadlist-laypage-normal'), "count": $selector.find('input[name="totalRow"]').val() || 10, "limit": $selector.find('input[name="pageSize"]').val() || 10, "curr": $selector.find('input[name="pageNumber"]').val(), "groups": 5, "prev": '', "next": '', "theme": "#1E9FFF" }; var ajaxUrl = '/phoenix2/composite/render/v1/pageRender/node/' + nodeObj.pageId + '/' + nodeObj.relationId + '/' + nodeObj.relationType + '/' + nodeObj.appId + '/' + nodeObj.nodeId function paginationBack(props) { try { layui && layui.use(function () { var laypage = layui.laypage; var layPageObject = Object.assign({}, props, { jump: function (obj, first) { //首次不执行 if (!first) { $.ajax({ url: ajaxUrl, data: { appVersion: nodeObj.appVersion, appIsDev: nodeObj.appIsDev, pageNum: obj.curr, pageSize: obj.limit }, dataType: 'html', success: function (data) { $(' [data-new-auto-uuid="' + nodeObj.nodeId + '"]').find(".block-download-container-replace").html($(`
${data}
`).find('.block-download-container-replace').html()); console.log('shouci'); opeart(); } }) } } }) laypage.render(layPageObject); }); } catch (e) { console.log(e) } } if(parseInt(props.count) > parseInt(props.limit)) { paginationBack(props); } // 表单验证 $selector.find("a[accessform=true]").unbind("click").bind("click", function () { var $that = $(this); var dwnurl = $(this).attr("dwnurl"); var url = "/phoenix/admin/download/formPop"; var encodeFileId = $.trim($(this).attr("encodeFileId")); var postData = {}; postData["fileId"] = encodeFileId; phoenixSite.ajax({ url: url, type: "post", data: postData, done: function (response) { var downloadAccessFormId = "downloadAccessForm_" + encodeFileId; $("#" + downloadAccessFormId).remove(); var cateId = $that.attr("cateid"); var ipAddress = window.location.hostname; if (cateId) { var localStorageCate = cateId + ipAddress; if (localStorage.getItem(localStorageCate) == 0) { try { var previewImg = $selector.find(".preview-file[encodefileid=" + encodeFileId + "]"); var prewImgUrl = $(".preview-file[encodefileid=" + encodeFileId + "]").attr("data-new_file_url") || ""; if (previewImg && previewImg.length > 0) { $("body").append('
'); try { $("#box-img-preview").lightGallery({ thumbnail: false }) } catch (error) { console.log(error) } $("#box-img-preview").find("img").click(); setTimeout(function () { $("#box-img-preview").remove(); $("#lg-zoom-in").addClass("fa"); $(".lg-toolbar").find("#lg-download").attr("href", dwnurl) }, 200); return } var tempwindow = window.open("_blank"); if (!!tempwindow.location) tempwindow.location = dwnurl; else window.location.href = dwnurl } catch (e) { console.log(e) } return } } $("body").append(response).promise().done(function () { var localStorageCate1 = cateId + ipAddress; $(".sitewidget-inquire .form-horizontal").on("submit", function () { localStorage.setItem(localStorageCate1, "0") }) }); var prewImgUrl = $(".preview-file[encodefileid=" + encodeFileId + "]").attr("data-new_file_url") || ""; $(".pop-downloadList .sitewidget-inquire form fieldset").prepend(''); if (prewImgUrl) $(".pop-downloadList .sitewidget-inquire form fieldset").prepend(''); $(".pop-downloadList .sitewidget-inquire form fieldset").prepend(''); var downloadPop = $("#" + downloadAccessFormId); downloadPop.fadeIn(); downloadPop.find("a.pop-close").unbind("click").bind("click", function (ev) { downloadPop.fadeOut(); ev.stopPropagation() }); var thisWidget = $(".pop-downloadList"); var countrySelect = thisWidget.find("select[title='country']"); var countryPlaceholder = ""; if (countrySelect.length > 0) $.ajax({ url: "/phoenix/admin/user/getCountries", type: "post", dataType: "json", data: {}, success: function (res) { if (res.countriesList && res.countriesList.length > 0) { countryPlaceholder = res.defaultDesc != "" ? res.defaultDesc : "please select"; var options = '"; if (!res.isTw && res.lanCode) $.each(res.countriesList, function (i, obj) { options += '" }); else if (!res.lanCode) $.each(res.countriesList, function (i, obj) { options += '" }); else if (res.isTw) $.each(res.countriesList, function (i, obj) { options += '" }); countrySelect.html(options) } } }); countrySelect.on("change", function () { if (thisWidget.find(".province").length > 0) { thisWidget.find(".province").remove(); if (thisWidget.find(".city").length > 0) thisWidget.find(".city").remove() } $(this).find("option:selected").val($(this).find("option:selected").text()); if ($(this).val()) { var _this = this; $.ajax({ url: "/phoenix/admin/user/getAllCountry", type: "post", dataType: "json", data: { province: $(this).find("option:selected").data("key") }, success: function (res) { if (res.provinceList && res.provinceList.length > 0) { var selectDom = '"; $(_this).after(selectDom) } } }) } }); thisWidget.on("change", ".province", function () { if (thisWidget.find(".city").length > 0) thisWidget.find(".city").remove(); var addVal = ""; var countryVal = countrySelect.find("option:selected").text(); addVal += countryVal; if ($(this).val()) { var _this = this; addVal += "_" + $(this).val(); if (countrySelect.find("option:selected").data("key") == "China") $.ajax({ url: "/phoenix/admin/user/getCity", type: "post", dataType: "json", data: { city: $(this).find("option:selected").data("key") }, success: function (res) { if (res.cityList && res.cityList.length > 0) { var selectDom = '"; $(_this).after(selectDom) } } }) } countrySelect.find("option:selected").val(addVal) }); thisWidget.on("change", ".city", function () { var addVal = ""; var countryVal = countrySelect.find("option:selected").text(); var privinceVal = thisWidget.find(".province").val(); addVal += countryVal + "_" + privinceVal; if ($(this).val()) addVal += "_" + $(this).val(); countrySelect.find("option:selected").val(addVal) }) } }) }); // 密码访问 $selector.find("a[accessauth=true]").unbind("click").bind("click", function () { var $that = $(this); var dwnurl = $(this).attr("dwnurl"); var url = "/phoenix/admin/download/accessPasswordPop"; var encodeFileId = $.trim($(this).attr("encodeFileId")); var postData = {}; postData["fileId"] = encodeFileId; var downloadAccessFormId = "downloadAccessForm_" + encodeFileId; phoenixSite.ajax({ url: url, type: "post", data: postData, done: function (response) { $("#" + downloadAccessFormId).remove(); var downloadAccessPasswordId = "downloadAccessPassword_" + encodeFileId; $('#' + downloadAccessPasswordId).remove(); $('body').append(response); bindEvent4SubmitAccessPassword(downloadAccessPasswordId); } }) }); function bindEvent4SubmitAccessPassword(downloadAccessPasswordId) { var downloadPop = $('#' + downloadAccessPasswordId); downloadPop.fadeIn(); downloadPop.find('a.pop-close').unbind('click').bind('click', function (ev) { downloadPop.fadeOut(); ev.stopPropagation(); }); downloadPop.find(".pop-input").on("input propertyChange", function () { if ($(this).val() != "") { $(this).nextAll(".err-tip").hide(); } }); downloadPop.find('a[submitAccessPassword=true]').unbind('click').bind('click', function () { var encodeFileId = $.trim(downloadPop.find('input[name=encodeFileId]').val()); var previewImg = $selector.find(".preview-img-btn[encodefileid=" + encodeFileId + "]"); var prewImgUrl = $selector.find(".preview-img-btn[encodefileid=" + encodeFileId + "]").attr("data-new_file_url") || ""; var url = '/phoenix/admin/download/submitAccessPassword'; var postData = {}; postData['fileId'] = $.trim(downloadPop.find('input[name=encodeFileId]').val()); postData['accessPassword'] = $.trim(downloadPop.find('input[name=accessPassword]').val()); postData['dp'] = "0"; phoenixSite.ajax({ url: url, type: 'post', data: postData, done: function (result) { result = $.parseJSON(result); if ($.isEmptyObject(result)) { downloadPop.fadeOut(); return; } if (result['authAccessPassword']) { var error = $selector.find('.access-auth-error-tips').val() || 'Password is wrong' downloadPop.find('.err-tip').html(error).show(); return; } downloadPop.fadeOut(); window.open(result['url']); } }) }) } } })(window, jQuery);